import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        /**
         * 是否需要强制登录
         */
        forcedLogin: false,
        hasLogin: false,
		userInfo:{}
    },
    mutations: {
        login(state,userInfo) {
			// console.log(userInfo)
            // state.userName = userName || '新用户';
			state.hasLogin = true;
			state.userInfo = userInfo;
			uni.setStorage({//缓存用户登陆状态
			    key: 'userInfo',  
			    data: userInfo  
			}) 
        },
        logout(state) {
			
			// uni.request({
			// 	url:'/api/logout',
			// 	data:null,
			// 	method: 'POST',
			// 	header: {
			// 		'X-Requested-With': 'XMLHttpRequest',
			// 		'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
			// 	},
			// 	success(res) {
			// 		console.log(res)
			// 	}
			// })
			
            // state.userName = "";
            state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({  
			    key: 'userInfo'  
			})
        }
    },
	actions: {
	
	}
})

export default store
